package com.freight.base.controller;

import com.freight.base.entity.Area;
import com.freight.base.entity.City;
import com.freight.base.service.AreaService;
import com.freight.base.vo.AreaListVo;
import com.freight.base.vo.AreaVo;
import com.freight.core.base.FreightLessBaseController;
import com.freight.core.common.annotation.SecretAnnotation;
import com.freight.core.common.utils.PageUtil;
import com.freight.core.common.utils.ResultUtil;
import com.freight.core.common.vo.PageVo;
import com.freight.core.common.vo.Result;
import com.freight.core.common.vo.SearchVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author huyingtai
 */
@Slf4j
@RestController
@Api(description = "区域维表管理接口")
@RequestMapping("/freight/area")
@Transactional
public class BaseAreaController extends FreightLessBaseController<Area, Long> {

    @Autowired
    private AreaService areaService;

    @Override
    public AreaService getService() {
        return areaService;
    }

    @RequestMapping(value = "/getByAreaList", method = RequestMethod.POST)
    @ApiOperation(value = "根据省份code获取城市列表")
    public Result<List<AreaListVo>> getByAreaList(String code) {

        List<AreaListVo> page = areaService.getByAreaList(code);
        return new ResultUtil<List<AreaListVo>>().setData(page);
    }



    @RequestMapping(value = "/getByCondition", method = RequestMethod.GET)
    @ApiOperation(value = "多条件分页获取")
    public Result<Page<Area>> getByCondition(Area area, SearchVo searchVo, PageVo pageVo) {

        Page<Area> page = areaService.findByCondition(area, searchVo, PageUtil.initPage(pageVo));
        return new ResultUtil<Page<Area>>().setData(page);
    }

    @RequestMapping(value = "/getAreaVoLevel", method = RequestMethod.GET)
    @ApiOperation(value = "获取区域")
    public Result<AreaVo> getAreaVoLevel(String areaCode) {
        AreaVo areavo = areaService.getAreaVoLevel(areaCode);
        return new ResultUtil<AreaVo>().setData(areavo);
    }
}
